#ifndef BIT_WIN_ROLES_H
#define BIT_WIN_ROLES_H


#include <Qt>
#include <QBitArray>


namespace BitWin
{


// BitWin model item data role, mocking the plain integral data
struct role_t
{
    typedef int value_t;

    enum
    {
        BitwiseDataRole=Qt::UserRole,
        HexDataRole,
        DecDataRole,
        NumRoles
    };

    role_t();
    explicit role_t(value_t value_);

    value_t value() const;
    operator int() const;

private:
    value_t _value;
};


// The set of BitWin item data roles
class RolesSet
{
    QBitArray _data;

    static int valueBitPos(int value);
    static int roleBitPos(role_t role);

    static const QBitArray DATA_INITIALIZER;

public:

    RolesSet();
    RolesSet(role_t role);

    // Bitwise operators are used for adding roles to the set
    // and test whether the particular role is in the set.
    // HACK! operator| has the operator|= semantics just for
    // syntactic sugar.

    RolesSet& operator|(role_t role);
    bool operator&(role_t role);
};


RolesSet operator|(role_t rhs, role_t lhs);

extern const role_t BitwiseDataRole, HexDataRole, DecDataRole;


// Are needed for backwards compatibility
#define BITWISE_DATA_ROLE (BitwiseDataRole)
#define HEX_DATA_ROLE (HexDataRole)
#define DEC_DATA_ROLE (DecDataRole)


} // BitWin namespace end


#endif
